import { ResourceApi } from "./resource-api";
import { GlobalConfig, ResourceType, Status } from "../modules";
import { Storage } from "../Storage";



/**
 * resoruce api for configuration.
 */
export class ConfApi extends Storage<GlobalConfig> implements ResourceApi<GlobalConfig> {
    
    getAll(): GlobalConfig {
        let res: GlobalConfig  = this.storageGet('CONF', '{"notifactionTemplate":"提示","intervalMs":"10000","hideNotifactionDetail":false,"notificationTemplate":"{RULE_TYPE}{RULE_VALUE},天啦噜，抓紧操作！"}');
        return res;
    }
    update(t: GlobalConfig) {
        let res: GlobalConfig = this.storageGet('CONF', '{"notifactionTemplate":"提示","intervalMs":"10000","hideNotifactionDetail":false,"notificationTemplate":"{RULE_TYPE}{RULE_VALUE},天啦噜，抓紧操作！"}');
        for (let key in GlobalConfig) {
            res[key] = t[key];
        }
        this.storageSet("CONF", res);
    }
    
    remove(t: GlobalConfig){
        throw new Error("Method not implemented.");
    }

    disabled() {
        let res = this.getAll();
        res.status = Status.OFF;
        this.update(res);
    }

    enabled() {
        let res = this.getAll();
        res.status = Status.ON;
        this.update(res);
    }

    isEnabled():boolean {
        let res = this.getAll();
        return res.status === Status.ON;
    }


}